'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {	
	const store = db.collection("store");
	let res
	if(event.type=='烘焙'){
		res = await store
		.aggregate()
		.match({
			"bread_type":true
		})
		.lookup({
			from: 'good', 
			localField: '_id', 
			foreignField: 'store_id', 
			as: 'goodList' 
		})
		.end()
	}
	if(event.type=='饮品'){
		res = await store
		.aggregate()
		.match({
			"drink_type":true
		})
		.lookup({
			from: 'good', 
			localField: '_id', 
			foreignField: 'store_id', 
			as: 'goodList' 
		})
		.end()
	}
	if(event.type=='简餐'){
		res = await store
		.aggregate()
		.match({
			"meal_type":true
		})
		.lookup({
			from: 'good', //要联查哪个表
			localField: '_id', //本表字段
			foreignField: 'store_id', //关联字段
			as: 'goodList' //别名
		})
		.end()
	}
	
	return res;
};
